import ComApiHttp from './../http/comApiHttp'
import PY from './Pinyin.service'
export default class Car{
  //获取品牌
  getCarBrand(type){
   return new Promise((resolve)=>{
     ComApiHttp.openApiAxios({
       url: '/carType/brandsQuery',
       data: {grade: type},
       success: (data) => {
         resolve(data)
       }
     })
   })
  }
  //获取车型  得到不同数据
  getCarTypeInfor(params){
    return new Promise((resolve,reject)=>{
      ComApiHttp.openApiAxios({
        url: '/carType/carTypeList',
        data: params,
        success: (data) => {
          resolve(data)
        }
      })
    })
  }
//获取排量
  getCarDisplacementData(params){
    return new Promise((resolve,reject)=>{
      ComApiHttp.openApiAxios({
        url: '/carType/carTypeInfoList',
        data: params,
        success: (data) => {
          resolve(data)
        }
      })
    })
  }
  //获取年份
  getCarYearData(params){
    return new Promise((resolve,reject)=>{
      ComApiHttp.openApiAxios({
        url: '/data/vehicle/listAllYears',
        data: params,
        success: (data) => {
          resolve(data)
        }
      })
    })
  }
  //获取年份
  getCarDetailInfor(params){
    return new Promise((resolve,reject)=>{
      ComApiHttp.openApiAxios({
        url: '/data/vehicle/query',
        data: params,
        success: (data) => {
          resolve(data)
        }
      })
    })
  }
  getLetterArr(brandData){
    let codeArr = [];
    brandData.forEach((item, index) => {
      let code = PY.turn(item.cname);
      codeArr.push(item.cname);
      item.code = code
    });
    return PY.turn(codeArr)
  }
  dealBrandData(brandData,letterArr){
    // 排序
    let newBrandData = [];
    brandData.sort((a, b) => {
      return a.code.charCodeAt(0) - b.code.charCodeAt(0)
    });
    letterArr.forEach((code) => {
      let itemObj = {
        content: [],
        code: ''
      };
      brandData.forEach((item) => {
        if (item.code === code) {
          itemObj.content.push(item);
          itemObj.code = code;
        }
      });
      newBrandData.push(itemObj)
    });
    return newBrandData
  }

}